Advanced iOS App Architecture by By René Cacheaux & By René Cacheaux && Josh Berlin & By Josh Berlin && René Cacheaux

Advanced iOS App Architecture by By René Cacheaux & By René Cacheaux && Josh Berlin & By Josh Berlin && René Cacheaux

Author:By René Cacheaux & By René Cacheaux && Josh Berlin & By Josh Berlin && René Cacheaux
Language: eng
Format: epub
Publisher: Ray Wenderlich


Reusing views on navigation

Reusing views on navigation makes state management harder. Each time you present a new screen, you need to make sure the state is reset back to the original state. The onboarding flow is an example of reusing views on navigation.

OnboardingViewController drives navigation from WelcomeViewController to SignInViewController. As you saw in the Driving Navigation — Combination section above, OnboardingViewController initially shows a WelcomeViewController. OnboardingViewController pushes a SignInViewController onto the navigation stack when the user taps the Sign In button.

You can find the View Controller file in Koober_iOS/Onboarding:

public class OnboardingViewController: NiblessNavigationController { // ... // Child View Controllers let welcomeViewController: WelcomeViewController let signInViewController: SignInViewController let signUpViewController: SignUpViewController // ... func presentWelcome() { pushViewController(welcomeViewController, animated: false) } func presentSignIn() { pushViewController(signInViewController, animated: true) } func presentSignUp() { pushViewController(signUpViewController, animated: true) } }

UINavigationController reuses views when moving backwards. OnboardingViewController holds a reference to the welcome view controller while displaying the sign-in view controller. When the user taps the Back button, the navigation stack doesn’t create a new welcome screen.

The onboarding view controller must ensure the welcome screen is in the correct state when the navigation stack pops the sign-in screen.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.